package com.rfzn.compose1

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Checkbox
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.rfzn.compose1.data.DataCenter.todos
import com.rfzn.compose1.data.Todo
import com.rfzn.compose1.ui.theme.Compose1Theme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Compose1Theme {

                TodoList(todos)
            }
        }
    }

    @Composable
    private fun TodoList(todos:List<Todo>) {
        Surface(
            modifier = Modifier.padding(16.dp),
            elevation = 8.dp,
            shape = RoundedCornerShape(8.dp)
        ) {
            LazyColumn(Modifier.fillMaxWidth()) {

                items(todos)
                { todo ->
                    Row(
                        verticalAlignment = Alignment.CenterVertically,modifier = Modifier.padding(8.dp)
                    ) {
                        Checkbox(checked = todo.completed, onCheckedChange = {
                            todo.completed=it
                        })
                        Text(text = todo.name)
                    }
                }


            }
        }
    }

    @Preview(showBackground = true)
    @Composable
    fun TodoListPreview() {

        TodoList(todos)
    }


}


